package org.jflame.commons.excel.convertor;

import org.jflame.commons.convert.Converter;
import org.jflame.commons.convert.ConvertibleType;
import org.jflame.commons.util.CollectionHelper;

import java.util.Locale;
import java.util.Set;

import org.apache.commons.lang3.tuple.ImmutablePair;

public class BoolToTextConverter implements Converter<Boolean,String>, ConvertibleType {

    private String trueText;
    private String falseText;

    public BoolToTextConverter() {
        // System.out.println(Locale.getDefault());
        if (Locale.CHINESE.getLanguage()
                .equals(Locale.getDefault()
                        .getLanguage())) {
            trueText = "是";
            falseText = "否";
        } else {
            trueText = "Yes";
            falseText = "No";
        }
    }

    @Override
    public String convert(Boolean source) {
        return source ? trueText : falseText;
    }

    public void setTrueText(String trueText) {
        this.trueText = trueText;
    }

    public void setFalseText(String falseText) {
        this.falseText = falseText;
    }

    @Override
    public Set<ImmutablePair<Class<?>,Class<?>>> getConvertibleTypes() {
        return CollectionHelper.newSet(ImmutablePair.of(Boolean.class, String.class),
                ImmutablePair.of(boolean.class, String.class));
    }

}
